﻿using FreeSql.DataAnnotations;
using FreeSql;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace EONFULLSIN2.Models.Entity.Base
{
    /// <summary>
    /// 添加接口
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public interface IEntityAdd<TKey> where TKey : struct
    {
        /// <summary>
        /// 创建者用户Id
        /// </summary>
        long? CreatedUserId { get; set; }

        /// <summary>
        /// 创建者
        /// </summary>
        string CreatedUserName { get; set; }

        /// <summary>
        /// 创建者姓名
        /// </summary>
        string CreatedUserRealName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        DateTime? CreatedTime { get; set; }
    }

    /// <summary>
    /// 删除接口
    /// </summary>
    public interface IDelete
    {
        /// <summary>
        /// 是否删除
        /// </summary>
        bool IsDeleted { get; set; }
    }

    /// <summary>
    /// 修改接口
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public interface IEntityUpdate<TKey> where TKey : struct
    {
        /// <summary>
        /// 修改者Id
        /// </summary>
        long? ModifiedUserId { get; set; }

        /// <summary>
        /// 修改者
        /// </summary>
        string ModifiedUserName { get; set; }

        /// <summary>
        /// 修改者姓名
        /// </summary>
        string ModifiedUserRealName { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        DateTime? ModifiedTime { get; set; }
    }

    

    public interface IEntity<TKey>
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        TKey Id { get; set; }
    }

    public interface IEntity : IEntity<long>
    {
    }

    public class Entity<TKey> : IEntity<TKey>
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [Description("主键Id")]
        [Column(Position = 1, IsIdentity = true, IsPrimary = true)]
        [JsonProperty(Order = -30)]
        [JsonPropertyOrder(-30)]
        public virtual TKey Id { get; set; }
    }

    public class Entity : Entity<long>
    {
    }

    /// <summary>
    /// 实体创建
    /// </summary>
    public class EntityAdd<TKey> : Entity<TKey>, IEntityAdd<TKey> where TKey : struct
    {
        /// <summary>
        /// 创建者用户Id
        /// </summary>
        [Description("创建者用户Id")]
        [Column(Position = -23, CanUpdate = false)]
        public virtual long? CreatedUserId { get; set; }

        /// <summary>
        /// 创建者用户名
        /// </summary>
        [Description("创建者用户名")]
        [Column(Position = -22, CanUpdate = false), MaxLength(60)]
        public virtual string CreatedUserName { get; set; }

        /// <summary>
        /// 创建者姓名
        /// </summary>
        [Description("创建者姓名")]
        [Column(Position = -21, CanUpdate = false), MaxLength(60)]
        public virtual string CreatedUserRealName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Description("创建时间")]
        [Column(Position = -20, CanUpdate = false)]
        public virtual DateTime? CreatedTime { get; set; }
    }

    /// <summary>
    /// 实体创建
    /// </summary>
    public class EntityAdd : EntityAdd<long>
    {
    }

    /// <summary>
    /// 实体修改
    /// </summary>
    public class EntityUpdate<TKey> : EntityAdd<TKey>, IEntityUpdate<TKey> where TKey : struct
    {
        /// <summary>
        /// 修改者用户Id
        /// </summary>
        [Description("修改者用户Id")]
        [Column(Position = -13)]
        [JsonProperty(Order = 10000)]
        [JsonPropertyOrder(10000)]
        public virtual long? ModifiedUserId { get; set; }

        /// <summary>
        /// 修改者用户名
        /// </summary>
        [Description("修改者用户名")]
        [Column(Position = -12), MaxLength(60)]
        [JsonProperty(Order = 10001)]
        [JsonPropertyOrder(10001)]
        public virtual string ModifiedUserName { get; set; }

        /// <summary>
        /// 修改者姓名
        /// </summary>
        [Description("修改者姓名")]
        [Column(Position = -11), MaxLength(60)]
        [JsonProperty(Order = 10001)]
        [JsonPropertyOrder(10001)]
        public virtual string ModifiedUserRealName { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        [Description("修改时间")]
        [JsonProperty(Order = 10002)]
        [JsonPropertyOrder(10002)]
        [Column(Position = -10)]
        public virtual DateTime? ModifiedTime { get; set; }
    }

    /// <summary>
    /// 实体修改
    /// </summary>
    public class EntityUpdate : EntityUpdate<long>
    {
    }

    /// <summary>
    /// 实体删除
    /// </summary>
    public class EntityDelete<TKey> : EntityUpdate<TKey>, IDelete where TKey : struct
    {
        /// <summary>
        /// 是否删除
        /// </summary>
        [Description("是否删除")]
        [Column(Position = -9)]
        public virtual bool IsDeleted { get; set; } = false;
    }

    /// <summary>
    /// 实体删除
    /// </summary>
    public class EntityDelete : EntityDelete<long>
    {

    }

    /// <summary>
    /// 实体基类
    /// </summary>
    public class EntityBase<TKey> : EntityDelete<TKey> where TKey : struct
    {

    }

    public class EntityBase : EntityBase<long>
    {

    }
}
